﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.IBUS;
using SD.Entities;
using SD.IDAL;
using SD.DAL;

namespace SD.BUS
{
    public class SupportingMaterialBIZ : BaseBIZ, ISupportingMaterialBIZ
    {
        #region ISupportingMaterialBIZ Members

        /// <summary>
        /// Get list supportingMaterial
        /// </summary>
        /// <param name="includeInactive"></param>
        /// <returns>Data table</returns>
        public System.Data.DataTable ListSupportingMaterial(bool includeInactive)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// List all Supporting Materials for an appropriate organization
        /// </summary>
        /// <param name="orgId">ID of the organization</param>
        /// <returns>List of Supporting Materials</returns>
        public System.Data.DataTable ListByOrgId(string orgId, Boolean includeInactive)
        {
            DataTable dtbResult = new DataTable();
            dtbResult.Columns.Add("SupportingMaterialID");
            dtbResult.Columns.Add("URL");
            dtbResult.Columns.Add("Description");
            dtbResult.Columns.Add("Type");
            dtbResult.Columns.Add("AddedBy");
            dtbResult.Columns.Add("AddedDate");

            try
            {
                ISupportingMaterialDAO smDAO = new SupportingMaterialDAO();
                List<SupportingMaterial> lstSM = smDAO.GetByOrgId(orgId, true);
                //Get SupportingMaterial from list SupportingMaterial
                foreach (SupportingMaterial sm in lstSM)
                {
                    dtbResult.Rows.Add(sm.SupportingMaterialId, sm.URL, sm.Description, 
                                        sm.Type != null ? sm.Type.RefValue: "N/A", 
                                        sm.AddedBy != null ? sm.AddedBy.Account : "N/A",
                                        sm.AddedDate.ToShortDateString());
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return dtbResult;
        }

        /// <summary>
        /// Get all Supporting Material
        /// </summary>
        /// <param name="includeInactive">Indicate whether inactive object will be included</param>
        /// <returns>List of Supporting material</returns>
        public List<SupportingMaterial> GetAll(bool includeInactive)
        {
            List<SupportingMaterial> result = new List<SupportingMaterial>();

            try
            {
                ISupportingMaterialDAO smDAO = new SupportingMaterialDAO();
                result = smDAO.GetAll(includeInactive);
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return result;
        }

        /// <summary>
        /// Get all supportingMaterial by orgid
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="includeInactive"></param>
        /// <returns>SupportMaterial</returns>
        public List<SD.Entities.SupportingMaterial> GetByOrgId(string orgId, Boolean includeInactive)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Get all supportingMaterial by supportingMaterial
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="includeInactive"></param>
        /// <returns>SupportMaterial</returns>
        public SD.Entities.SupportingMaterial GetById(Guid smId)
        {
            throw new NotImplementedException();
        }

        #region CRUD

        /// <summary>
        /// Insert supportingMaterial
        /// </summary>
        /// <param name="sm"></param>
        public void Insert(SD.Entities.SupportingMaterial sm)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Update supportingMaterial
        /// </summary>
        /// <param name="sm"></param>
        public void Update(SD.Entities.SupportingMaterial sm)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Delete supportingMaterial
        /// </summary>
        /// <param name="smId"></param>
        public void Delete(string smId)
        {
            throw new NotImplementedException();
        }

        #endregion

        #endregion

        #region ISupportingMaterialBIZ Members


        public List<SupportingMaterial> SelectByOrgId(string orgId, int pageNumber, int pageSize, out int totalPages, bool includeInactive)
        {
            ISupportingMaterialDAO smDAO = new SupportingMaterialDAO();

            try
            {
                return smDAO.SelectByOrgId(orgId, pageNumber, pageSize, out totalPages, includeInactive);
            }
            catch (Exception ex)
            {                
                throw ex;
            }
        }

        #endregion
    }
}
